package com.gf.service.impl;

import com.gf.bean.User;
import com.gf.dao.UserMapper;
import com.gf.service.UserService;
import com.gf.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class UserServiceImpl implements UserService {
    @Override
    public List<User> selectAll() {
        SqlSession sqlSession = MybatisUtils.getsqlSession();
        List<User> users = sqlSession.getMapper(UserMapper.class).selectAll();
        MybatisUtils.closesqlSession(sqlSession);
        return users;
    }

    @Override
    public User selectByUsername(String strname) {
        SqlSession sqlSession = MybatisUtils.getsqlSession();
        User user = sqlSession.getMapper(UserMapper.class).selectByUsername(strname);
        MybatisUtils.closesqlSession(sqlSession);
        return user;
    }

    @Override
    public int insert(User record) {
        SqlSession sqlSession = MybatisUtils.getsqlSession();
        int insert = sqlSession.getMapper(UserMapper.class).insert(record);
        MybatisUtils.closesqlSession(sqlSession);
        return insert;
    }

    @Override
    public User checkUserroomnumberandtel(int user_id) {
        SqlSession sqlSession = MybatisUtils.getsqlSession();
        User user = sqlSession.getMapper(UserMapper.class).checkUserroomnumberandtel(user_id);
        MybatisUtils.closesqlSession(sqlSession);
        return user;
    }

    @Override
    public int updateuserroomandtel(User record) {
        SqlSession sqlSession = MybatisUtils.getsqlSession();
        int flag = sqlSession.getMapper(UserMapper.class).updateuserroomandtel(record);
        MybatisUtils.closesqlSession(sqlSession);
        return flag;
    }
}
